package com.jlastu.dlxy_androidapp.view.order;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jlastu.dlxy_androidapp.R;
import com.jlastu.dlxy_androidapp.adapter.OrderAdapter;
import com.jlastu.dlxy_androidapp.entity.OrderItem;

import java.util.ArrayList;
import java.util.List;


public class ConfirmOrderFragment extends Fragment {

    private RecyclerView mRecyclerView;
    private OrderAdapter mAdapter;

    @SuppressLint({"WrongViewCast", "MissingInflatedId"})
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.confirm_order_layout, container, false);

        // 初始化RecyclerView
        mRecyclerView = view.findViewById(R.id.lv_order_items);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setHasFixedSize(true);

        // 示例数据，实际应从服务器获取
        List<OrderItem> orderItems = getMockOrderItems();

        // 设置Adapter
        mAdapter = new OrderAdapter(orderItems);
        mRecyclerView.setAdapter(mAdapter);

        // 设置点击事件
        Button btnConfirmOrder = view.findViewById(R.id.btn_confirm_order);
        btnConfirmOrder.setOnClickListener(v -> {
            // 实现确认订单逻辑
            confirmOrder();
        });

        return view;
    }

    private void confirmOrder() {
        // 实现确认订单的逻辑，比如发送网络请求
    }

    private List<OrderItem> getMockOrderItems() {
        // 这里返回模拟的商品数据列表
        return new ArrayList<>();
    }
}